/**
* 
*	PushMenu类
*	作者：邓磊
*	时间：2016年7月4日 16:40:43
*	作用：上传微信菜单
*	域：无
*
*/
package com.eptok.weixin.util;


import org.apache.log4j.Logger;

import net.sf.json.JSONObject;
import yspay.express.bean.menu.Button;
import yspay.express.bean.menu.ClickButton;
import yspay.express.bean.menu.ComplexButton;
import yspay.express.bean.menu.Menu;
import yspay.express.bean.menu.ViewButton;
import yspay.express.store.WxConstant;
import yspay.express.store.WxStore;
import yspay.express.util.CommonUtil;


public class PushMenu {
	
	private static final Logger log = Logger.getLogger(AESUtil.class);
	/*private static String appid = "wx67e0267aca26ea04";
	private static String appsecret="9e6ced3cdd65f730d27eedbb7e779a68";*/
	
	public static void pushMenu()
	{
//		String domain = "http://zxhdl.hicp.net";
		String domain = "http://denglei9018.oicp.net";
		
		ViewButton b1 = new ViewButton();
		b1.setName("寄快递");
		b1.setType("view");
		b1.setUrl(domain+"/express_m/weixin/indexKdy.do");
		
		ViewButton b2 = new ViewButton();
		b2.setName("我的快递");
		b2.setType("view");
		b2.setUrl(domain+"/express_m/weixin/user/expressMySend.do");
		
		ComplexButton b3 = new ComplexButton();
		b3.setName("更多服务");
		
		ViewButton b3_1 = new ViewButton();
		b3_1.setName("个人中心");
		b3_1.setType("view");
		b3_1.setUrl(domain+"/express_m/weixin/index.do");
		
		ClickButton b3_2 = new ClickButton();
		b3_2.setName("自助服务");
		b3_2.setType("click");
		b3_2.setKey(WxConstant.KEY_HELP_YOURSELF);
		
		ClickButton b3_3 = new ClickButton();
		b3_3.setName("人工客服");
		b3_3.setType("click");
		b3_3.setKey(WxConstant.KEY_HELP_WORKER);
		
		Button[] b3_sub = new Button[3];
		b3_sub[0] = b3_1;
		b3_sub[1] = b3_2;
		b3_sub[2] = b3_3;
		b3.setSub_button(b3_sub);
		
		Menu menu = new Menu();
		Button[] b = new Button[3];
		b[0] = b1;
		b[1] = b2;
		b[2] = b3;
		menu.setButton(b);
		JSONObject json = JSONObject.fromObject(menu);
		log.info(json.toString());
		String accessToken = WxStore.getAccessToken();
		JSONObject ret = CommonUtil.httpsRequest(WxConstant.MENU_CREATE_URL.replace("ACCESS_TOKEN", accessToken), CommonUtil.REQ_POST, json.toString());
		log.info("创建菜单结果："+ret.toString());
	}

	public static void main(String[] args) {
		pushMenu();
	}
	
}
